package com.gxitsky.utils;

import org.yaml.snakeyaml.Yaml;

import java.io.*;

/**
 * @author gxing
 * @desc Yaml Tool
 * @date 2022/4/4
 */
public class YamlHelper {

    private YamlHelper() {
    }

    private static final Yaml YAML = new Yaml();

    public static <T> T parseYaml(File file, Class<T> clazz) {
        try {
            return parseYaml(new FileInputStream(file), clazz);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public static <T> T parseYaml(InputStream inputStream, Class<T> clazz) {
        return YAML.loadAs(inputStream, clazz);
    }

    public static <T> T parseYaml(String yamlData, Class<T> clazz) {
        return YAML.loadAs(yamlData, clazz);
    }

    public static <T> T parseYaml(Reader io, Class<T> clazz) {
        return YAML.loadAs(io, clazz);
    }

}
